package com.gba.mark.labelResult.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gba.mark.labelResult.entity.LabelResult;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface LabelResultMapper extends BaseMapper<LabelResult> {
    @Select("SELECT " +
            "COUNT(*) " +
            "FROM " +
            "`label_result` l, `origin` o, `article` a " +
            "WHERE " +
            "DAY(l.post_date) = DAY (NOW()) " +
            "AND l.user_id = #{userId} " +
            "AND l.origin_id = o.id " +
            "AND o.article_id = a.id " +
            "AND a.group_id = #{groupId} ")
    Integer countDaily(@Param("userId") int userId, @Param("groupId") int groupId);

    @Select("SELECT " +
            "COUNT(*) " +
            "FROM " +
            "`label_result` l, " +
            "`origin` o, " +
            "`article` a " +
            "WHERE " +
            "l.post_date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) " +
            "AND l.user_id = #{userId} " +
            "AND l.origin_id = o.id " +
            "AND o.article_id = a.id " +
            "AND a.group_id = #{groupId}")
    Integer countWeek(@Param("userId") int userId, @Param("groupId") int groupId);

    @Select("SELECT " +
            "COUNT(*) " +
            "FROM " +
            "`label_result` l, " +
            "`origin` o, " +
            "`article` a " +
            "WHERE " +
            "l.user_id = #{userId} " +
            "AND l.origin_id = o.id " +
            "AND o.article_id = a.id " +
            "AND a.group_id = #{groupId}")
    Integer countTotal(@Param("userId") int userId, @Param("groupId") int groupId);
}